#ifndef HTTPREQUEST_H
#define HTTPREQUEST_H


#include <QNetworkReply>


class HTTPRequest : public QObject
{
    Q_OBJECT

signals:
    //升级完毕
    //errorType是错误类型，为1是客户端，为0是服务端
    void s_finished(QNetworkReply::NetworkError error, int status_code);  //下载完成


public:
    explicit HTTPRequest(QObject *parent = nullptr);
    virtual ~HTTPRequest();


public:
    bool get(QUrl url);
    bool post(QUrl url, QByteArray baData);

protected:
    bool checkURL(QUrl url);


private slots:
    //注意，一下几个函数不一定按顺序触发，比如有可能先finished,再readyRead!!!
    void onReadyRead(); //有数据到来，要保存
    void onDownloadProgress(qint64 a,qint64 b);             //下载进度
    void onFinished(QNetworkReply *reply);                  //完成下载，reply用于接收消息
    void onReplyError(QNetworkReply::NetworkError e);       //下载错误
    void onReplySslErrors(const QList<QSslError> &errors);  //下载错误


private:
    Q_DISABLE_COPY(HTTPRequest)


//数据成员
public:
    QNetworkRequest m_NetWorkRequest;
    QByteArray m_baHttpData;    //下载保存的数据

private:
    QNetworkReply *m_pNetWorkReply;
};

#endif // HTTPREQUEST_H
